package CCRMClient.Controllers;

import java.util.ArrayList;

import Common.SERVER_COMMANDS;
import Common.ServerRequest;
import Common.Entities.CustomersInTemplate;
import Common.Entities.MarketingTemplate;


/**
 * This class manage the actions that can be done on marketing templates by client side
 * @author AL
 *
 */
public class TemplateManager 
{
	
	/**
	 * This method create a server request to add a new Marketing Template to the DB.
	 * @param templateID - Marketing template ID
     * @param templateName - Marketing template name
     * @param templateDescription - Marketing template description
     * @param templateMessage - Marketing template message
     * @param templateStatus - Marketing template status
     * @param productID - Product ID which is related to the template
	 * @return - server request with command ADD_TEMPLATE, and the new template object for inserting
	 */
	public static ServerRequest addTemplate (String templateID, String templateName, String templateDescription,
			String templateMessage,String templateStatus,String productID) 
	{
		MarketingTemplate tmp = new MarketingTemplate (Integer.parseInt(templateID), templateName, templateDescription,
				templateMessage, "in building process" ,Integer.parseInt(productID));
		return new ServerRequest (SERVER_COMMANDS.ADD_TEMPLATE, null, tmp);
	}
	
	/**
	 * This method create a server request to search a Marketing Template in the DB.
	 * @param templateID - Marketing template ID
     * @param templateName - Marketing template name
     * @param templateDescription - Marketing template description
     * @param templateMessage - Marketing template message
     * @param templateStatus - Marketing template status
     * @param productID - Product ID which is related to the template
	 * @return - server request with command SEARCH_TEMPLATE, and the new template object for searching
	 */
	public static ServerRequest SearchTemplate (String templateID, String templateName, String templateDescription,
			String templateMessage,String templateStatus,String productID) 
	{
		MarketingTemplate tmp = new MarketingTemplate (Integer.parseInt(templateID), templateName, templateDescription,
				templateMessage, templateStatus ,Integer.parseInt(productID));
		return new ServerRequest (SERVER_COMMANDS.SEARCH_TEMPLATE, null, tmp);
	}
	
	/**
	 * This method create a server request to view a Marketing Template from the DB.
	 * @param templateID - Marketing template ID
     * @param templateName - Marketing template name
     * @param templateDescription - Marketing template description
     * @param templateMessage - Marketing template message
     * @param templateStatus - Marketing template status
     * @param productID - Product ID which is related to the template
	 * @return - server request with command VIEW_TEMPLATE, and the new template object for viewing
	 */
	public static ServerRequest ViewTemplate (String templateID, String templateName, String templateDescription,
			String templateMessage,String templateStatus,String productID) 
	{
		MarketingTemplate tmp = new MarketingTemplate (Integer.parseInt(templateID), templateName, templateDescription,
				templateMessage, templateStatus ,Integer.parseInt(productID));
		return new ServerRequest (SERVER_COMMANDS.VIEW_TEMPLATE, null, tmp);
	}
	
	
	/**
	 * This method create a server request to update a Marketing Template in the DB.
	 * @param templateID - Marketing template ID
     * @param templateName - Marketing template name
     * @param templateDescription - Marketing template description
     * @param templateMessage - Marketing template message
     * @param templateStatus - Marketing template status
     * @param productID - Product ID which is related to the template
	 * @return - server request with command UPDATE_TEMPLATE, and the new template object for updating
	 */
	public static ServerRequest UpdateTemplate (String templateID, String templateName, String templateDescription,
			String templateMessage,String templateStatus,String productID) 
	{
		MarketingTemplate tmp = new MarketingTemplate (Integer.parseInt(templateID), templateName, templateDescription,
				templateMessage, templateStatus ,Integer.parseInt(productID));
		return new ServerRequest (SERVER_COMMANDS.UPDATE_TEMPLATE, null, tmp);
	}
	
	/**
	 * This method create a server request to search a Marketing Template in the DB by status.
	 * @param command - The command SEARCH_TEMPLATE_BY_STATUS
	 * @param search - string for query.
	 * @return a server request with the command and search string.
	 */
	public static ServerRequest SearchTemplateByStatus(SERVER_COMMANDS command, String search)
	{
		return new ServerRequest (command, null, search);
	}
	
	/**
	 * This method create a server request to retrieve all customer with rate over a given value
	 * @param command - relevant server command
	 * @param rate - minimal customer rate
	 * @param templateID - template ID to associate with
	 * @return - a server request with the relevant parameters
	 */
	public static ServerRequest SearchCustRates(SERVER_COMMANDS command, int rate, int templateID) {
		Integer data[] = {rate, templateID};
		return new ServerRequest (command, null, data);
	}
	
	/**
	 * This method create server command to associate a list of selected customers to a template
	 * @param command - server command to perform
	 * @param toAssign - list of customers and templates
	 * @return - relevant server request
	 */
	public static ServerRequest AssignCustomersToTemplate(SERVER_COMMANDS command, ArrayList<CustomersInTemplate> toAssign) {
		return new ServerRequest (SERVER_COMMANDS.ASSIGN_CUSTOMERS_TO_TEMPLATE, null, toAssign);
	}
}
